package classification;

import java.util.Date;
import java.util.Hashtable;

import main.Paycheck;

import salesReceiptTransaction.SalesReceipt;
import schedule.Period;

public class CommissionClassification implements PaymentClassification {
	private double baseRate;
	private double commissionRate;
	private Hashtable<Date, SalesReceipt> salesReceipts = new Hashtable<Date, SalesReceipt>();

	public CommissionClassification(double baseRate, double commissionRate) {
		this.baseRate = baseRate;
		this.commissionRate = commissionRate;
	}

	public double getBaseRate() {
		return baseRate;
	}

	public double getCommissionRate() {
		return commissionRate;
	}

	public void addSalesReceipt(SalesReceipt receipt) {
		salesReceipts.put(receipt.getDate(), receipt);
	}

	public SalesReceipt getSalesReceipt(Date time) {
		return (SalesReceipt) salesReceipts.get(time);
	}

	public double calculatePay(Paycheck paycheck) {
		double salesTotal = 0;
		for (SalesReceipt receipt : salesReceipts.values()) {
			if (Period.isInPayPeriod(receipt.getDate(),
					paycheck.getPayPeriodStartDate(),
					paycheck.getPayPeriodEndDate())) {
				salesTotal += receipt.getSaleAmount();
			}
		}

		return baseRate + (salesTotal * commissionRate * 0.01);
	}

	public String toString() {
		return "$" + baseRate + " + " + commissionRate + "% sales commission";
	}
}
